<?php

namespace App\Console\Commands\HbGjPolicyCheck;

use Curl\CurlService\CurlService;

class PolicyCheckStatic
{
    public static function policyCheck($value,$policyUploadInterface){

        //先获取价格


            $url = env('CRM_SCAN_COM_BASE').'/api/flightline/getPrice';

            $param = [
                'flight_line' => [
                    'id'    => 1,
                    'depart_city_code' => $value['depart_city_code'],
                    'arrived_city_code' => $value['arrived_city_code'],
                ],
                'flight_code' => $value['flight_code'],
                'resource' => 14,
                'thread_type' => 14,
                'hs_code'   => substr($value['flight_code'],0,2),
                'date'      => $value['date'],
                'task_type' => 2,
            ];

            $res = CurlService::post($url,$param);var_dump($res);
            if ($res && !empty($res['data'])) {
                $flight = $res['data'][0];

                $delete = false;

                if (empty($flight['cabins'][0]['r_cabin'])) {

                    $delete = true;
                }


                if (!empty($flight['cabins'][0]['r_cabin']) && $flight['cabins'][0]['r_seat'] < 5) {

                    $delete = true;
                }


                if ($delete) {

                    $specialPolicyInterface = resolve('App\Repositories\Ota\Ctrip\Policy\Contracts\SpecialPolicyInterface');
                    $res = $specialPolicyInterface->delete([$value['policy_id']]);var_dump($res);
                    if (isset($res['TradeResult']) && isset($res['TradeResult']['Result']) && !empty($res['TradeResult']['Result']['SuccessList'])) {

                        $data['status'] = 3;
                        $policyUploadInterface->update(['id'=>$value['id']],$data);
                    }
                }

            } else {

                /*$specialPolicyInterface = resolve('App\Repositories\Policy\Contracts\SpecialPolicyInterface');
                $res = $specialPolicyInterface->delete([$value['policy_id']]); var_dump($res);
                if (isset($res['TradeResult']) && isset($res['TradeResult']['Result']) && !empty($res['TradeResult']['Result']['SuccessList'])) {

                    $data['status'] = 3;
                    $policyUploadInterface->update(['id'=>$value['id']],$data);
                }*/
            }

            /*if ($value['created_at'] < date('Y-m-d H:i:s',strtotime('-60minute'))) {

                $specialPolicyInterface = resolve('App\Repositories\Policy\Contracts\SpecialPolicyInterface');
                $res = $specialPolicyInterface->delete([$value['policy_id']]); var_dump($res);

                $data['status'] = 3;
                $policyUploadInterface->update(['id' => $value['id']], $data);
            }*/



    }
}